package base;

import holder.ItemHolder;

import java.util.ArrayList;
import java.util.List;

import manager.DownLoadManager;
import utils.UIUtils;
import activity.DetailActivity;
import android.content.Intent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Toast;
import bean.AppInfoBean;



/**
 * baseAdapter的基类
 * @author Anson-pc
 *
 */
public class BaseItemAdapter extends SuperBaseAdapter<AppInfoBean>{
	

	/**
	 * 定义集合保存观察者
	 */
	private List<ItemHolder> mItemHolders = new ArrayList<ItemHolder>();
	

	public List<ItemHolder> getmItemHolders() {
		return mItemHolders;
	}

	public void setmItemHolders(List<ItemHolder> mItemHolders) {
		this.mItemHolders = mItemHolders;
	}


	public BaseItemAdapter(AbsListView ablistView, List<AppInfoBean> mDatas) {
		super(ablistView, mDatas);
	}

	@Override
	protected BaseHolder<AppInfoBean> getSpecialHolder(int position) {
		
		ItemHolder itemHolder = new ItemHolder();
		
		mItemHolders.add(itemHolder);
		
		
		//添加到观察者里面
		DownLoadManager.getInstance().addObserver(itemHolder);
		
		return itemHolder;
	}
	

	//普通条目的点击事件
	@Override
	public void onNormalItemClick(AdapterView<?> parent, View view,
			int position, long id) {
		//通过Intent对象实现页面的跳转
		Intent intent = new Intent(UIUtils.getContext(),DetailActivity.class);
		intent.putExtra("packageName", mDataSources.get(position).packageName);
		//新开一个任务栈
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		UIUtils.getContext().startActivity(intent);
	}



}
